package com.kang.learn;

/**
 * @description: 实例学习法
 * @author: User
 * @date: 2021/10/5
 */
public class SynOneDemo {

    private static int count = 0;

    //region 多线程问题

    /**
     * 执行结果是一个不确定的值，但是总比1000小
     */
    public static void incr(){
        try {
            Thread.sleep(1);
            count++;
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    // endRegion

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 1000 ; i++) {
            new Thread(()->SynOneDemo.incr()).start();
        }
        Thread.sleep(4000);
        System.out.println("result:" + count);
    }
}
